{template 'delivery/header'}
<div class="page" id="page-delivery-order">
	<header class="bar bar-nav common-bar-nav">
		<a class="icon pull-left fa fa-arrow-left back hide"></a>
		<h1 class="title">配送管理{if $status == 3}(<span id="time">10</span>秒后自动刷新){/if}</h1>
	</header>
	{template 'delivery/nav'}
	<div class="content infinite-scroll" data-distance="50" data-min="{$min}" data-status="{$status}">
		<div class="buttons-tab">
			<a href="{php echo $this->createMobileUrl('dyorder', array('status' => 3));}" class="button {if $status == 3}active{/if}">待抢</a>
			<a href="{php echo $this->createMobileUrl('dyorder', array('status' => 4));}" class="button {if $status == 4}active{/if}">配送中</a>
			<a href="{php echo $this->createMobileUrl('dyorder', array('status' => 5));}" class="button {if $status == 5}active{/if}">配送成功</a>
			<a href="{php echo $this->createMobileUrl('dyorder', array('status' => 6));}" class="button {if $status == 6}active{/if}">订单取消</a>
		</div>
		{if empty($orders)}
		<div class="no-data">
			<div class="bg"></div>
			<p>没有任何订单哦～</p>
		</div>
		{else}
		<div class="order-list">
			{if $status == 3}
			<ul>
				{loop $orders $order}
				<li class="row delivery-wait">
					{if $order['delivery_type'] == 1}
						<div class="delivery-type bg-danger">店内</div>
					{else}
						<div class="delivery-type bg-success">平台</div>
					{/if}
					<div class="order-ls-info col-80">
						<p>取货门店: {$stores[$order['sid']]['title']}</p>
						<p>取货地址: {$stores[$order['sid']]['address']}</p>
						<p>送货地址: {$order['address']}</p>
						{if $order['delivery_type'] == 2}
						<p>配送费用: {$order['deliveryer_fee']}元</p>
						{/if}
					</div>
					<div class="order-ls-btn col-20">
						<a href="javascript:;" class="order-collect" data-id="{$order['id']}" data-delivery-type="{$order['delivery_type']}" data-fee="{$order['deliveryer_fee']}" data-status="4">抢</a>
					</div>
				</li>
				{/loop}
			</ul>
			{else}
			<ul>
				{loop $orders $order}
					<li class="delivery-others">
						{if $order['delivery_type'] == 1}
							<div class="delivery-type bg-danger">店内</div>
						{else}
							<div class="delivery-type bg-success">平台</div>
						{/if}
						<a class="order-ls-info external" href="{php echo $this->createMobileUrl('dyorder', array('op' => 'detail', 'id' => $order['id']));}">
							<div class="order-ls-tl">下单人:{$order['username']}<span class="{$delivery_status[$order['delivery_status']]['color']}">{$delivery_status[$order['delivery_status']]['text']}</span></div>
							<div class="order-ls-date">{php echo date('Y-m-d H:i:s', $order['addtime']);}<span>编号: {$order['id']}</span></div>
							<div class="order-ls-dl">
								<div class="row">
									<div class="col-25">取货地址:</div>
									<div class="col-75 align-right">{$stores[$order['sid']]['address']}</div>
								</div>
								<div class="row">
									<div class="col-25">送货地址:</div>
									<div class="col-75 align-right">{$order['address']}</div>
								</div>
								<div class="row">
									<div class="col-25">手机　号:</div>
									<div class="col-75 align-right">{$order['mobile']}</div>
								</div>
							</div>
							<div class="order-ls-sum">共{$order['num']}件，合计：¥{$order['final_fee']}</div>
						</a>
						{if $order['delivery_status'] == 4}
							<div class="order-ls-btn">
								<a href="tel:{$order['mobile']}">呼叫顾客</a>
								<a href="javascript:;" class="order-notice" data-id="{$order['id']}">微信通知</a>
								<a href="javascript:;" class="scanqrcode">扫码确认</a>
								<a href="javascript:;" class="order-success" data-id="{$order['id']}" data-status="5">手动确认</a>
							</div>
						{/if}
					</li>
					{/loop}
				</ul>
			{/if}
			<div class="infinite-scroll-preloader hide">
				<div class="preloader"></div>
			</div>
		</div>
		{/if}
	</div>
</div>
<script>
$(function(){
	$(document).on("click", ".order-collect", function() {
		var id = $(this).data('id');
		if(!id) {
			return false;
		}
		var delivery_type = $(this).data('delivery-type');
		var delivery_fee = $(this).data('fee');
		var status = $(this).data('status');
		var tips = "该订单是平台单, 配送完成后将获得" + delivery_fee + '元配送费, 确定接单吗';
		if(delivery_type == 1) {
			var tips = "该订单是店内单, 确定接单吗";
		}
		$.confirm(tips, function() {
			$.post("{php echo $this->createMobileUrl('dyorder', array('op' => 'collect'))}", {id: id, status: status}, function(data){
				var result = $.parseJSON(data);
				if(result.message.errno != 0) {
					$.toast(result.message.message);
				} else {
					$.toast(result.message.message, location.href);
				}
			});
		});
	});

	//自动刷新
	{if $status == 3}
		setInterval(function(){
			var time = parseInt($('#time').html());
			if(time >= 1) {
				time--;
				$('#time').html(time);
			} else {
				location.reload();
			}
		}, 1000);
	{/if}
});
</script>
{template 'delivery/common'}
{template 'delivery/footer'}